package org.example.smartEducationBackend.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.example.smartEducationBackend.entity.POJO.Favorite;
import org.example.smartEducationBackend.entity.POJO.Resource;
import org.example.smartEducationBackend.mapper.FavoriteMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class FavoriteService {
    @Autowired
    private FavoriteMapper favoriteMapper;
    public Favorite getFavorite(Integer userId,Integer videoId) {
        QueryWrapper<Favorite> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        queryWrapper.eq("video_id",videoId);

        Favorite favorite1 = favoriteMapper.selectOne(queryWrapper);
        return favorite1;
    }

    public Integer add(Favorite favorite) {
        int insert = favoriteMapper.insert(favorite);
        return insert;
    }

    public void delete(Favorite favorite) {
        QueryWrapper<Favorite> favoriteQueryWrapper = new QueryWrapper<>();
        favoriteQueryWrapper.eq("user_id",favorite.getUserId());
        favoriteQueryWrapper.eq("video_id",favorite.getVideoId());
        favoriteMapper.delete(favoriteQueryWrapper);
    }
}
